using Aspire.Hosting;

var builder = DistributedApplication.CreateBuilder(args);

var keycloak = builder
    .AddKeycloak("keycloak", 6001)
    .WithDataBindMount(@"C:\Data\Docker\Overflow\keycloak");

var postgres = builder
    .AddPostgres("postgres", null, null, 5432)
    .WithDataBindMount(@"C:\Data\Docker\Overflow\postgres")
    .WithPgAdmin();

var typesenseApiKey = builder.AddParameter("typesense-api-key", "abc", secret: true);
var typesense = builder.AddContainer("typesense", "typesense/typesense", "29.0")
    .WithArgs("--data-dir", "/data", "--api-key", typesenseApiKey, "--enable-cors")
    .WithBindMount(@"C:\Data\Docker\Overflow\typesense\data", "/data")
    .WithHttpEndpoint(8108, 8108, "typesense");

var typesenseEndpoint = typesense.GetEndpoint("typesense");

var productDb = postgres.AddDatabase("productDb");

var rabbitmq = builder.AddRabbitMQ("messaging")
    .WithBindMount("C:\\Data\\Docker\\Overflow\\rabbitmq", "/rabbitmq-data")
    .WithManagementPlugin(port: 15672)
    ;

builder
    .AddProject<Projects.ProductService>("product-service")
    .WithReference(keycloak)
    .WaitFor(keycloak)
    .WithReference(rabbitmq)
    .WaitFor(rabbitmq)
    .WithReference(productDb)
    .WaitFor(productDb);

builder.AddProject<Projects.SearchService>("search-service")
    .WithEnvironment("typesense-api-key", typesenseApiKey)
    .WithReference(rabbitmq)
    .WaitFor(rabbitmq)
    .WithReference(typesenseEndpoint)
    .WaitFor(typesense);

builder.Build().Run();
